//
//  OilTopupViewController.m
//  EasyToTesco
//
//  Created by mc on 16/1/31.
//  Copyright © 2016年 Jack. All rights reserved.
//

#import "OilTopupViewController.h"
#import "OilTopUpTableViewCell.h"
#import "HeaderFileForEasyToTesco.h"
#import "ReadLoginData.h"

//石油充值详情页面头文件
#import "OilChangeViewController.h"



@interface OilTopupViewController ()<UITableViewDataSource, UITableViewDelegate>
{
    
}

@property (nonatomic, strong)UITableView *Oiltableview;
@end

@implementation OilTopupViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    NSDictionary *dic = [ReadLoginData readLoginData];
    if (dic.allKeys.count == 0) {
        UIAlertView *alview = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您尚未登录,请登录后再次操作" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        alview.tag = 1008610;
        [alview show];
    }else {
        [self addOiltopupUI];
    
    }
    
    
    
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (alertView.tag == 1008610) {
        [self dismissViewControllerAnimated:YES completion:nil];
        //        self.view.window.rootViewController = [[RegisterViewController alloc]
        //        init];
        
    } else {
        
    }
}

- (void)addOiltopupUI {
    self.view.backgroundColor =[UIColor colorWithRed:238/255. green:238/255. blue:238/255. alpha:1];
    
    [self addOilTopUI];
    [self addOilTabel];
    
    [self addOtherLabel];
    
}

- (void)addOilTabel {
    UITableView *Oiltableview = [[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.firstView.frame), WEITH, 80) style:UITableViewStylePlain];
    Oiltableview.delegate = self;
    Oiltableview.dataSource = self;
    Oiltableview.scrollEnabled = NO;
    Oiltableview.rowHeight = 60;
    self.Oiltableview = Oiltableview;
    [self.view addSubview:self.Oiltableview];
}

- (void)addOilTopUI {
    UIImageView *image1 = [[UIImageView alloc] initWithFrame:CGRectMake(10, (self.secondView.frame.size.height-20)/2, 20, 20)];
    image1.image = [UIImage imageNamed:@"goback-icon.png"];
    [self.secondView addSubview:image1];
    self.leftBtn.hidden = YES;
    
    UIButton *goBackBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    goBackBtn.frame = CGRectMake(0, 0, self.secondView.frame.size.height, self.secondView.frame.size.height);
    [goBackBtn addTarget:self action:@selector(gobackClick) forControlEvents:UIControlEventTouchUpInside];
    [self.secondView addSubview:goBackBtn];
    self.titleLabel.text = @"石油充值";
}
- (void)gobackClick {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)addOtherLabel {
    CGFloat marc = 8*WEITHRATE;
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(marc, CGRectGetMaxY(self.Oiltableview.frame)+marc/2, WEITH/2-marc*2, 30)];
    titleLabel.text = @"常见问题";
    titleLabel.font = [UIFont systemFontOfSize:16];
    [self.view addSubview:titleLabel];
    
;
    NSArray *BtnTitleArray = @[@"如何申请加油卡?", @"充值成功后,还需要哪些操作?", @"什么是充值卡?"];
    
    
    for (NSInteger i=0; i < 3; i++) {
        UIButton *otherBtnOne = [UIButton buttonWithType:UIButtonTypeCustom];
        otherBtnOne.frame = CGRectMake(marc, (CGRectGetMaxY(titleLabel.frame)+marc)+(marc+30)*i, WEITH/2+marc*2, 30);
        UILabel *Titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(marc, (CGRectGetMaxY(titleLabel.frame)+marc)+(marc+30)*i, WEITH/2+marc*2, 30)];
        Titlelabel.font = [UIFont systemFontOfSize:14];
        Titlelabel.textAlignment = NSTextAlignmentLeft;
        Titlelabel.text = [NSString stringWithFormat:@"%@", BtnTitleArray[i]];

        otherBtnOne.tag = 900+i;
        [otherBtnOne addTarget:self action:@selector(OtherBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [self.view addSubview:Titlelabel];
        [self.view addSubview:otherBtnOne];
    }
    
    
    
    
}
//下方小字体链接
- (void)OtherBtnClick:(UIButton *)button {
    NSLog(@"第%ld个button", button.tag);
}


#pragma mark -- UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *identifierOilCell = @"OilTopUpTableViewCell";
    OilTopUpTableViewCell *OilCell = [tableView dequeueReusableCellWithIdentifier:identifierOilCell];
    if (OilCell == nil) {
        OilCell = [[[NSBundle mainBundle]loadNibNamed:@"OilTopUpTableViewCell" owner:nil options:nil] lastObject];

        OilCell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
            OilCell.OilImage.image = [UIImage imageNamed:@"sh-icon.png"];
            OilCell.OilName.text = @"中国石化";
            OilCell.OilDetail.text = @"加油卡充值";

    return OilCell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

#pragma mark -- UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 10;
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *footerView = [[UIView alloc] init];
    footerView.backgroundColor =[UIColor colorWithRed:238/255. green:238/255. blue:238/255. alpha:1];
    return footerView;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"%ld---%ld", indexPath.section, indexPath.row);
    
    OilChangeViewController *oilChangeView = [[OilChangeViewController alloc] init];
    [self presentViewController:oilChangeView animated:YES completion:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
